#ifndef RULEITEMMODEL_H
#define RULEITEMMODEL_H

#include <QAbstractItemModel>
#include "global.h"

class RuleItemModel : public QAbstractItemModel
{
    Q_OBJECT
public:
    enum ModelColumn {
        AETitle,
        Printer,
        EmptyImage,
        Border,
        TrueSize,

        ColumnCount,
    };

    explicit RuleItemModel(QObject *parent = 0);
    ~RuleItemModel() { qDeleteAll(ruleList); }

    void getRuleList(QList<PrintRule*> &rules) {
        rules = ruleList;
        ruleList.clear();
    }
    static void getRulesFromFile(QList<PrintRule*> &rules);

    int rowCount(const QModelIndex &parent) const { if (parent.isValid()) return 0; else return ruleList.size(); }
    int columnCount(const QModelIndex &parent) const { if (parent.isValid()) return 0; else return ColumnCount; }
    QModelIndex parent(const QModelIndex &/*child*/) const { return QModelIndex(); }
    QModelIndex index(int row, int column, const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
    bool setData(const QModelIndex &index, const QVariant &value, int role);
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;
    bool insertRows(int row, int count, const QModelIndex &parent);
    bool removeRows(int row, int count, const QModelIndex &parent);
    Qt::ItemFlags flags(const QModelIndex &index) const;

    static QString densityType2String(DensityType type) {
        switch (type) {
        case DT_Client:
            return tr("Client");
        case DT_Black:
            return tr("Black");
        case DT_White:
            return tr("White");
        default:
            return QString();
        }
    }

signals:

public slots:
    bool saveData();

private:
    void setupModel();


    QList<PrintRule*> ruleList;

};

#endif // RULEITEMMODEL_H
